﻿/******************************************************    
文件名:operate.cs
版权  (c)  2010-11-23 淘渺圈圈工作室
作者:黄媛媛
创建日期:2010-11-23
维护人员:黄媛媛
维护日期:2010-11-23
文件功能描述:金属材料热处理网络学习平台_pdf查询操作
******************************************************/
using System;
using System.Collections.Generic;
using System.Text;

using Mmht.DB;
using System.Data;

namespace Mmht.BT
{
    public class GetPdf
    {
        private int _ctrNumber = 20;
        TablePdfDB tp = new TablePdfDB();
        /// <summary>
        /// pdf查询
        /// </summary>
        /// 参数：文件类型
        /// 课件
        /// 习题
        /// 标准
        /// 文献
        /// 教研文章
        /// 用于查询文件请求是否正确
        /// 返回数布尔值
        /// ///  Writer：黄媛媛
        ///Create Date：2010-12-02
        private bool CheckPdf(string type)
        {
            bool correct=false;
            switch (type)
            {
                case "课件": correct = true; break;
                case "习题": correct = true; break;
                case "标准": correct = true; break;
                case "文献": correct = true; break;
                case "教研文章": correct = true; break;
                default: correct = false; break;
            }
            return correct;
        }

        /// </summary>
        /// pdf查询
        /// <param name="type">文件类型</param>
        /// 课件
        /// 习题
        /// 标准
        /// 文献
        /// <param name="i">查询类型</param>
        /// 1查询全部的pdf
        /// 2查询推荐pdf
        /// 3查询点击率最高的100篇pdf
        /// <returns>返回datatable</returns>
        /// Writer：黄媛媛
        /// Create Date：2010-12-02
        private DataTable Get_Pdf(string type,int i)
        {
            DataTable dt = new DataTable();
            if (CheckPdf(type))
            {
                string sql = string.Empty;
                switch (i)
                {
                    case 1: sql = "select * from pdf where type='" + type + "'"; break;
                    case 2: sql = "select * from pdf where type='" + type + "' and iscommend =1"; break;
                    case 3: sql = "select top " + _ctrNumber.ToString()
                        + " * from pdf where type='" + type
                        + "' order by viewnum desc"; break;
                }
                operate op = new operate();
                dt = op.Query(sql);
            }
            else
            {
                dt = null;
            }
            return dt;
        }

        /// <summary>
        /// 查询全部的pdf文件
        /// </summary>
        /// <param name="type">文件类型</param>
        /// 课件
        /// 习题
        /// 标准
        /// 文献
        /// <returns>datatable</returns>
        /// Writer：黄媛媛
        /// Create Date：2010-12-02
        public DataTable Get_All_Pdf(string type)
        {
            return Get_Pdf(type, 1);
        }

        /// <summary>
        /// 查询全部的pdf文件
        /// </summary>
        /// <param name="type">文件类型</param>
        /// 课件
        /// 习题
        /// 标准
        /// 文献
        /// <returns>datatable</returns>
        /// Writer：黄媛媛
        /// Create Date：2010-12-02
        public DataTable Get_Recommended_Pdf(string type)
        {
            return Get_Pdf(type, 2);
        }

        /// <summary>
        /// 查询点记率最高得pdf文件
        /// </summary>
        /// <param name="type">文件类型</param>
        /// 课件
        /// 习题
        /// 标准
        /// 文献
        /// <returns>datatable</returns>
        /// Writer：黄媛媛
        /// Create Date：2010-12-02
        public DataTable Get_CTRtop_Pdf(string type, int ctrNumber)
        {
            this._ctrNumber = ctrNumber;
            return Get_Pdf(type, 3);
        }

        public DataRow GetPdfById(int id)
        {
            return tp.GetPdfById(id);
        }

        /// <summary>
        /// 选出点击率最高的top个pdf信息
        /// </summary>
        /// <param name="top">个数</param>
        /// <returns></returns>
        public DataTable GetCTRTopPdf(int top)
        {
            return tp.GetCTRTopPdf(top);
        }

        /// <summary>
        /// 选出点击率最高且被推荐的top个pdf信息
        /// </summary>
        /// <param name="top">个数</param>
        /// <returns></returns>
        public DataTable GetIsCommendTopPdf(int top)
        {
            return tp.GetIsCommendTopPdf(top);
        }
        public DataTable SelectPDF(string type) 
        {
            return tp.SelectPDF(type);
        }
        public DataTable SelectAllPDF() 
        {
            return tp.SelectAllPDF();
        }
        public bool DelPDF(string type,int id) 
        {
            return tp.DelPDF(type ,id);
        }
        public DataTable GetPdfByName(string name,string type) 
        {
            return tp.GetPdfByName(name,type );
        }
        public bool UpdatePDF(string name,string author,string remark,int id) 
        {
            return tp.UpdatePDF(name, author, remark, id);
        }
        public bool UpdatePDFbz(string name_cn,string name_en,string code,string remark,int id) 
        {
            return tp.UpdatePDFbz(name_cn ,name_en ,code ,remark ,id);
        }
        public bool Recommend(int id) 
        {
            return tp.Recommend(id);
        }
        public bool Unreommend(int id) 
        {
            return tp.Unrecommend(id);
        }
        public bool ClearViewnum(int id) 
        {
            return tp.ClearViewnum(id);
        }
        public bool ClearAllViewnum()
        {
            return tp.ClearAllViewnum();
        }

        /// <summary>
        /// pdf文件上传
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="type"></param>
        /// <param name="create_by"></param>
        public void UploadPdf(DataTable dt, string type, int create_by, DateTime create_at)
        {
            if (dt == null || dt.Rows.Count == 0)
            {
                return;
            }
            else
            {
                tp.UploadPdf(dt, type, create_by, create_at);
            }
        }

        public DataTable UploadPdfInfo(DateTime create_at, int create_by)
        {
            return tp.UploadPdfInfo(create_at,create_by);
        }

        public DataTable SearchPdf(string key)
        {
            return tp.SearchPdf(key);
        }
    }
}
